import Vue from "vue";
import App from "./App.vue";
import router from "./router";
import store from "./store";

// 配置 ElementUI
import ElementUI from "element-ui";
import "element-ui/lib/theme-chalk/index.css";
Vue.use(ElementUI);

// 配置 全局初始化样式
import "@/assets/css/reset.scss";

//引入icon
import "./assets/iconfont/iconfont.css";
// Vue.use(ElementUI)

//引入动画
import animate from "animate.css";

// 引入echarts
import * as echarts from "echarts";
Vue.prototype.$echarts = echarts;

Vue.config.productionTip = false;

router.beforeEach((to, from, next) => {
  //全局前置守卫
  //to : 将要进入的目标路由对象
  //from : 即将离开的目标路由对象
  //执行跳转的下一步钩子
  //如果是登入页，就判断token
  //如果不是登入也，就进入登入页
  let go = ["/login", "/duanxing", "/lingpai"];
  if (go.indexOf(to.path) != -1) {
    next();
  } else {
    let token = localStorage.getItem("token");
    if (token) {
      next();
    } else {
      next("/login");
    }
  }
});

new Vue({
  router,
  store,
  render: h => h(App)
}).$mount("#app");
